home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / db / esm-3.1 / esm-3 / usr / local / sm / src / include / LHDIRPAGE.h < prev    next >
Encoding:
C/C++ Source or Header  |  1996-05-05  |  7.0 KB  |  260 lines

  1. #ifndef __LHDIRPAGE_H__
  2. #define __LHDIRPAGE_H__
  3.  
  4. /*
  5.  *    $RCSfile: LHDIRPAGE.h,v $
  6.  *    $Revision: 1.1.1.1 $
  7.  *    $Date: 1996/05/04 21:55:07 $
  8.  */
  9. /**********************************************************************
  10. * EXODUS Database Toolkit Software
  11. * Copyright (c) 1991 Computer Sciences Department, University of
  12. *                    Wisconsin -- Madison
  13. * All Rights Reserved.
  14. *
  15. * Permission to use, copy, modify and distribute this software and its
  16. * documentation is hereby granted, provided that both the copyright
  17. * notice and this permission notice appear in all copies of the
  18. * software, derivative works or modified versions, and any portions
  19. * thereof, and that both notices appear in supporting documentation.
  20. *
  21. * THE COMPUTER SCIENCES DEPARTMENT OF THE UNIVERSITY OF WISCONSIN --
  22. * MADISON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" CONDITION.  
  23. * THE DEPARTMENT DISCLAIMS ANY LIABILITY OF ANY KIND FOR ANY DAMAGES
  24. * WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
  25. *
  26. * The EXODUS Project Group requests users of this software to return 
  27. * any improvements or extensions that they make to:
  28. *
  29. *   EXODUS Project Group 
  30. *     c/o David J. DeWitt and Michael J. Carey
  31. *   Computer Sciences Department
  32. *   University of Wisconsin -- Madison
  33. *   Madison, WI 53706
  34. *
  35. *     or exodus@cs.wisc.edu
  36. *
  37. * In addition, the EXODUS Project Group requests that users grant the 
  38. * Computer Sciences Department rights to redistribute these changes.
  39. **********************************************************************/
  40. #include "lh_extfuncs.h"  // change
  41. #include "LH_Hash.h"
  42.  
  43. /*
  44.  *    Size of a LHDIRPAGE (same as LHINDPAGE) defined in object.h
  45.  */
  46.  
  47. /*
  48.  *    load factor threshold is defaulted as 75%
  49.  */
  50. #define     LH_THRESHOLD        0.75
  51.  
  52. #ifdef __cplusplus            /* LHDIRPAGE defs for C++ only */
  53.  
  54. // 
  55. //    LHDIR page control structure 
  56. //
  57. struct LHDIRCONTROL {
  58.     LRC         lrc;            // for recovery
  59.     PID         selfID;         // id of this page
  60.     FOUR        curPos;            // position of next entry 
  61.     FOUR        M;              // number of primary pages
  62.     FOUR        P;              // pointer to next page to be splitted
  63.     ONE         I;              // current level
  64.     ONE            type;           // key type
  65.     ONE            height;            // the height of the directory tree            
  66.     ONE         rootFlag;        // flag to indicate if this is a root page
  67.     float        loadThreshold;    // the threshold of load factor
  68.     float        load;            // current load of primary pages
  69.     };
  70.  
  71.  
  72.  
  73. const LHDIR_MAGIC = 14021967;   // change
  74.  
  75. //
  76. //     LHDIR page definition
  77. //
  78. //const LH_TBLSIZE = 3;
  79. const LH_TBLSIZE = (BTREE_PAGESIZE - sizeof(LHDIRCONTROL) - 100) / sizeof(SHORTPID);
  80.  
  81. class LHDIRPAGE {
  82.     
  83.     // 
  84.     //    Physical undos and redos must access page directly
  85.     //
  86.     friend void undoLHash_fr(LOGRECORDHDR*);
  87.     friend void redoLHash_fr(LOGRECORDHDR*);
  88.  
  89.         LHDIRCONTROL    lhDirCtrl;                // control information
  90.         SHORTPID        indPid[LH_TBLSIZE];        // index page table
  91.  
  92.     public:
  93.         //
  94.         //    General queries
  95.         //
  96.         PID&        SelfID()        { return lhDirCtrl.selfID; }
  97.         int            Volume()        { return lhDirCtrl.selfID.volid; }
  98.         SMDATATYPE    KeyType()        { return (SMDATATYPE) lhDirCtrl.type; }
  99.         FOUR        Primary()        { return lhDirCtrl.M; }
  100.         FOUR        SplitPtr()        { return lhDirCtrl.P; }
  101.         int            Level()            { return (int) lhDirCtrl.I; }
  102.         float        Load()            { return lhDirCtrl.load; }
  103.         float        Threshold()        { return lhDirCtrl.loadThreshold; }
  104.         int            Height()        { return (int) lhDirCtrl.height; }
  105.         int            CurPos()        { return (int) lhDirCtrl.curPos; } 
  106.         int            IsRoot()        { return lhDirCtrl.rootFlag; }
  107.  
  108.         //
  109.         //    address of start of table
  110.         //
  111.         char*        FirstEntry()    { return (char*) &indPid[0]; }
  112.         
  113.         //
  114.         //    LRC 
  115.         //
  116.         LRC&        lrc()            { return lhDirCtrl.lrc; }
  117.  
  118.         //
  119.         //    Return TRUE if this page is safe
  120.         //
  121. //        int            IsSafe(LH_OPER oper, int maxKeyLen);
  122.  
  123.         //
  124.         //    Get the index page id at slot position within index table
  125.         //
  126.         SHORTPID    GetEntry(FOUR slot)    { 
  127.                                 ASSERT1( slot>=0 && slot < lhDirCtrl.curPos );
  128.                                 return indPid[slot]; 
  129.                                 }
  130.         //
  131.         //    Set the next entry to contain the new index page id.
  132.         //
  133.         void        SetNextEntry(SHORTPID indPage)    { 
  134.                                 ASSERT1( lhDirCtrl.curPos < LH_TBLSIZE );
  135.                                 indPid[lhDirCtrl.curPos] = indPage;
  136.                                 lhDirCtrl.curPos++;
  137.                                 }
  138.         //
  139.         //    UnSet the next entry to contain the new index page id.
  140.         //
  141.         void        UnSetNextEntry(SHORTPID unused /*indPage*/)    { 
  142.                                 ASSERT1( lhDirCtrl.curPos > 0 );
  143.                                 indPid[--lhDirCtrl.curPos] = NULLPID;
  144.                                 }
  145.  
  146.         //
  147.         //    Set the specified entry to contain the new index page id.
  148.         //    For original primary pages only
  149.         //
  150.         void        SetEntry(SHORTPID indPage, FOUR slot)    { 
  151.                                 ASSERT1( slot < INIT_PRIMARY );
  152.                                 // asserts may cause failure in recovery 
  153.                                 //  under debug mode.
  154.                                 // ASSERT1( lhDirCtrl.M == INIT_PRIMARY );
  155.                                 // ASSERT1( lhDirCtrl.curPos == INIT_PRIMARY );
  156.                                 indPid[slot] = indPage;
  157.                                 }
  158.  
  159.         //
  160.         //  Copy the whole directory page
  161.         //
  162.         //
  163.         void        CopyData(LHDIRPAGE* target) {
  164.                         bcopy((char*)indPid, (char*)target->indPid, 
  165.                                 LH_TBLSIZE*sizeof(SHORTPID));
  166.                          target->lhDirCtrl.height = lhDirCtrl.height;
  167.                         target->lhDirCtrl.curPos = lhDirCtrl.curPos;
  168.                         }
  169.  
  170.         //
  171.         //    Initialize a new directory page
  172.         //
  173.         void         Init(PID& const pid, int rootFlag, SMDATATYPE keyType) {
  174.                                 lhDirCtrl.selfID = pid;
  175.                                 lhDirCtrl.type = keyType;
  176.                                 lhDirCtrl.M = 0;
  177.                                 lhDirCtrl.P = 0;
  178.                                 lhDirCtrl.I = 0;
  179.                                 lhDirCtrl.load = 0.0;
  180.                                 lhDirCtrl.height = 1;
  181.                                 lhDirCtrl.curPos = 0;
  182.                                 lhDirCtrl.rootFlag = rootFlag;
  183.                                 lhDirCtrl.loadThreshold = LH_THRESHOLD; 
  184.                                 }
  185.         //
  186.         //  update the global index page count
  187.         //    only root directory page can perform the function
  188.         //
  189.         void         IncrCount() { ASSERT1(lhDirCtrl.rootFlag);
  190.                                   lhDirCtrl.M++;
  191.                                   }
  192.     
  193.         //
  194.         //    calculate the index value
  195.         //
  196.         int            IndexCalc(int keyLen, void* keyVal);
  197.  
  198.         //
  199.         //    calculate the directory capacity with given height
  200.         //
  201.         int            Capacity(int height);
  202.  
  203.         //
  204.         //  update function used in index page splitting
  205.         //
  206.         void        IndSplitUpdate(float oldFromLoad, float fromLoad,
  207.                                     float toLoad);
  208.         
  209.         //
  210.         //  update function used in index page shrinking
  211.         //
  212.         void        IndShrinkUpdate(float fromLoad, float toLoad, 
  213.                                     float newFromLoad);
  214.         
  215.         //
  216.         //    update function used in directory page splitting
  217.         //        reset curPos and increment height
  218.         //
  219.         void        DirSplitUpdate() {
  220.                                 lhDirCtrl.curPos = 0;
  221.                                 lhDirCtrl.height++;
  222.                                 }
  223.         //
  224.         //  update load change
  225.         //
  226.         void         LoadUpdate(float oldLoad, float newLoad);
  227.  
  228.         //
  229.         //  set load 
  230.         //
  231.         void        SetLoad(float load) {
  232.                         ASSERT1(lhDirCtrl.rootFlag);
  233.                         lhDirCtrl.load = load;
  234.                         }
  235.         //
  236.         //  set up load factor threshold
  237.         //
  238.         void        SetThreshold(float threshold) {
  239.                         ASSERT1(lhDirCtrl.rootFlag);
  240.                         lhDirCtrl.loadThreshold = threshold;
  241.                         }
  242.  
  243.         //
  244.         // set up height: used in bulk load only
  245.         //
  246.         void        SetHeight(int level) {
  247.                         lhDirCtrl.height = level;
  248.                         }
  249.                                 
  250.         //
  251.         //    Debugging utilities
  252.         //
  253.         int          CheckContent();
  254.         void        Print();
  255.     };
  256.  
  257. #endif        /* #ifdef C++ */
  258.  
  259. #endif __LHDIRPAGE_H__
  260.